package cn.edu.zxj.ojspring.controller;

import cn.edu.zxj.ojspring.model.Result;
import cn.edu.zxj.ojspring.model.compile.CompileRequest;
import cn.edu.zxj.ojspring.model.compile.CompileResponse;
import cn.edu.zxj.ojspring.service.CompileService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Description：编译管理
 *
 * @author: zxj
 * @date: 2024-02-21
 * @time: 17:46:41
 */
@RestController
@Slf4j
public class CompileController {

    @Autowired
    private CompileService compileService;

    @RequestMapping("/compile")
    public Result compile(@RequestBody CompileRequest compileRequest) {
        log.info("接收到用户提交代码的请求, compileRequest: {}", compileRequest);

        CompileResponse compileResponse = compileService.compileAndRun(compileRequest);
        if (compileResponse == null) {
            return Result.fail("内部出现错误, 请联系管理员~");
        }

        return Result.success(compileResponse);
    }
}
